#include "timer1.h"


crm_clocks_freq_type crm_clocks_freq_struct = {0};
void Timer1_init(void)
{
 /* enable tmr1 clock */
  crm_periph_clock_enable(CRM_TMR1_PERIPH_CLOCK, TRUE);
	
	  /* tmr1 configuration */
  /* time base configuration */
  //tmr_base_init(TMR1, 100, (crm_clocks_freq_struct.apb2_freq * 2 / 10000) - 1);
	tmr_base_init(TMR1, 50000, 25600); //1/64000
  tmr_cnt_dir_set(TMR1, TMR_COUNT_UP);
	
	  /* overflow interrupt enable */
  tmr_interrupt_enable(TMR1, TMR_OVF_INT, TRUE);

  /* tmr1 hall interrupt nvic init */
 // nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
  nvic_irq_enable(TMR1_OVF_TMR10_IRQn, Time10_preempt_priority, Time10_preempt_priority);

  /* enable tmr1 */
  tmr_counter_enable(TMR1, TRUE);
	
}

float pitch1,roll1,yaw1; 
void TMR1_OVF_TMR10_IRQHandler(void)
{
	static uint32_t num,data;
	
  if(tmr_interrupt_flag_get(TMR1, TMR_OVF_FLAG) == SET)
  {
		num++;
		
		if(num>1000)
		{
			num = 0;
			data++;
		}
    /* add user code... */
    //at32_led_toggle(LED3);
		//mpu_mpl_get_data(&pitch1,&roll1,&yaw1);
    tmr_flag_clear(TMR1, TMR_OVF_FLAG);
  }
}